package com.song.controller;

import com.song.pojo.Category;
import com.song.pojo.Items;
import com.song.service.CategoryService;
import com.song.service.ItemsService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 宋超
 * HP - the login name of the current user.
 * 2020/12/27 - the current system date.
 * 20:27 - the current system time.
 */
@Controller
public class IndexController {
    @Resource
    private ItemsService itemsService;
    @Resource
    private CategoryService categoryService;

    @RequestMapping("index.html")
    public String index(Model model){
        //调用查询商品列表的方法
        List<Items> itemsList = itemsService.findItemsList(null);

        //调用查询所有类别列表的方法
        List<Category> categoryList = categoryService.findCategoryList(null);

        //调用查询每个类型的商品列表
        List<Items> items = itemsService.findItemsListByCategoryId();

        //将数据放到模型中
        model.addAttribute("itemsList",itemsList);
        model.addAttribute("categoryList",categoryList);
        model.addAttribute("items",items);
        return "forward:/home.jsp";
    }




}
